package com.mdc.mansion.core.common.translate.impl;

import com.mdc.mansion.common.util.log.BusinessLogger;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.stereotype.Service;

import com.mdc.mansion.core.common.translate.TranslateLanguage;
import com.mdc.mansion.core.common.translate.TranslateService;
import com.mdc.mansion.core.common.translate.util.TranslateUtil;

/**<p>com.mdc.mansion.core.common.translate.impl.TranslateServiceImpl</p>
 * <p>Title: TranslateServiceImpl</p>
 * <p>Copyright: Copyright © 2010-2014</p>
 * @version 1.0
 */
@Service
public class TranslateServiceImpl implements TranslateService {

    @Override
    public String translate(String text, TranslateLanguage srcLanguage, TranslateLanguage targetLanguage) {
        String ret = ""; 
        try {
           ret =  TranslateUtil.translate(text, srcLanguage.getValue(), targetLanguage.getValue());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }

    @Override
    public String translate(String text, TranslateLanguage targetLanguage) {
        String ret = ""; 
        try {
           ret =  TranslateUtil.translate(text, targetLanguage.getValue());
           BusinessLogger.log("translate","ori:"+text+",target:"+targetLanguage.getValue()+",result:"+ret);
        } catch (Exception e) {
            e.printStackTrace();
            BusinessLogger.log("translate","ori:"+text+",target:"+targetLanguage.getValue()+",exception:"+ ExceptionUtils.getFullStackTrace(e));
        }
        return ret;
    }
 
}
